import { getAreaObj } from '@/utils/util'
import { getStore } from '@/utils/store'

const userInfo = getStore('userInfo') || {}

export const spotCheckForm = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '处理内容',
			prop: 'handleContent',
			type: 'textarea',
			maxlength: '500',
			rows: 1,
			showWordLimit: true,
			span: 24,
		},
	],
}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			label: '监控画面',
			prop: 'alarmPic',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 1,
			multiple: false,
			custome: 'img',
			viewDisplay: false,
			span: 24,
		},
		{
			label: '摄像头编号',
			prop: 'videoNum',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入摄像头编号' }],
		},
		{
			label: '摄像头位置',
			prop: 'videoLocation',
			type: 'input',
			span: 12,
		},
		{
			label: '楼层房间号',
			prop: 'videoFloor',
			// propName: 'videoFloorText',
			type: 'BuildRoomBed',
			deepLevel: 2,
			display: !(userInfo.classifyId == 4 && userInfo.userType == 3),
			span: 12,
		},
		{
			label: '状态',
			prop: 'handleStatus',
			type: 'select',
			dicData: [
				{
					label: '已处理',
					value: 1,
				},
				{
					label: '未处理',
					value: 2,
				},
			],
			span: 12,
		},
		{
			label: '报警时间',
			prop: 'alarmTime',
			type: 'datetime',
			format: 'YYYY年MM月DD日 HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			changeField: true,
			span: 12,
		},
		{
			label: '播放地址',
			prop: 'videoUri',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入播放地址' }],
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	labelWidth: '90px',
	column: [
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 12,
		},
		{
			label: '所属单位',
			prop: 'organizationName',
			type: 'input',
			span: 12,
		},
		{
			label: '摄像头编号',
			prop: 'videoNum',
			type: 'input',
			span: 12,
		},
		{
			label: '摄像头位置',
			prop: 'videoLocation',
			type: 'input',
			span: 12,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区', prop: 'areaName' },
		{ label: '所属单位', prop: 'organizationName' },
		{ label: '摄像头编号', prop: 'videoNum' },
		{ label: '摄像头位置', prop: 'videoLocation' },
		{ label: '监控画面', prop: 'alarmPic', custome: 'file' },
		{
			label: '状态',
			prop: 'handleStatus',
			custome: 'tag',
			dicData: [
				{
					label: '已处理',
					value: 1,
				},
				{
					label: '未处理',
					value: 2,
				},
			],
		},
		{ label: '报警时间', prop: 'alarmTime' },
		{ label: '摄像头地址', prop: 'videoPlay' },
		{
			label: '操作',
			prop: 'menu',
			width: 160,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_pbVideoAlarm_page',
	add: 'view_pbVideoAlarm_add',
	edit: 'view_pbVideoAlarm_edit',
	detail: 'view_pbVideoAlarm_view',
	authArea: 'authArea',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '行为分析监测',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'videoNum',
	exportMqTopic: '/ning/export/',
	loadOrgInfo: true,
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '处理',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
			condition: '(row)=>row.handleStatus == 2',
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],

	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			form = {
				...form,
				videoFloor: form.videoFloor?.join('/'),
			}
			resolve(form)
		})
	},
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(arr)
		})
	},
	dialogConfig: {
		width: '55%',
	},
	searchConfig,
	formConfig,
	tableConfig,
}
